package com.threadpool.mythread.case01;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @Author 李李李
 * @2020/4/25 22:55
 *
 * Callable 的应用
 * 相比Runable 可以抛出异常 有返回值 有缓存 高效
 *
 */
public class Case07 {
    public static void main(String[] args) throws Exception {

        MyThread myThread = new MyThread();
        FutureTask<String> futureTask = new FutureTask<>(myThread);
        new Thread(futureTask).start();
        new Thread(futureTask).start();
        String result = futureTask.get();
        System.out.println("result ===>" + result); //注意看console 打印为何少一句 call
    }
}

class MyThread implements Callable<String>{

    @Override
    public String call() throws Exception {
        System.out.println("call");
        return "我是 Call";
    }
}
